﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using CE.Provider;
using CE.Global;
using CE.AreaCountry;
using CE.TravelInsurance;

public partial class Provider_TravelInsurance_AddNewTravelInsurance : System.Web.UI.Page
{
    string PageName = "CXTI";
    string SubPageName = "CXTICT";
    const int PromoLength = 80;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        if (!IsPostBack)
        {

            LoadCompany();
            ddlProviderCompanyName.SelectedValue = Session[CE.Global.General.ProviderCompanyId].ToString();

            GetPolicyDoc();
            //GetPromotion();
            ClearFields();

            Int64 _taid;
            string _covertype;
            if ((Request.Params["TAID"] != null) && (Request.Params["Cov"] != null))
            {
                if (Int64.TryParse(Request.Params["TAID"].ToString(), out _taid))
                {
                    _covertype = Request.Params["Cov"].ToString();
                    ShowTADetails(_taid, _covertype);


                    string Promomesg = txtPromo.Text;
                    inputChars.Value = Promomesg.Length.ToString() + "/80 chars";
                }
            }
            else
            {
                inputChars.Value = "0/80 chars";
            }

        }

     
        this.txtPromo.Attributes.Add("onkeyup", "return isMaxLength(this);");
        
     
    }

    private void LoadCompany()
    {
        DataTable _dtCompany = General.GetComboItem("ProviderCompany", false);
        _dtCompany.DefaultView.Sort = "CompanyName asc";

        ddlProviderCompanyName.DataSource = _dtCompany.DefaultView.Table;
        ddlProviderCompanyName.DataTextField = _dtCompany.Columns[0].ColumnName.ToString();
        ddlProviderCompanyName.DataValueField = _dtCompany.Columns[1].ColumnName.ToString();
        ddlProviderCompanyName.DataBind();

        ddlProviderCompanyName.Items.Insert(0, new ListItem("Select", "-1"));
    }

    private void GetPolicyDoc()
    {
        ProviderPolicyDocumentList _policydoclist = new ProviderPolicyDocumentList();
        ProviderPolicyDocumentDB _policydb = new ProviderPolicyDocumentDB();

        _policydoclist = _policydb.GetProviderPolicyDocumentList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), "TI");

        if (_policydoclist != null)
        {
            ddlPolicyDoc.DataSource = _policydoclist;
            ddlPolicyDoc.DataTextField = "DocumentName";
            ddlPolicyDoc.DataValueField = "Documentid";
            ddlPolicyDoc.DataBind();
        }

        ddlPolicyDoc.Items.Insert(0, new ListItem("Select", "-1"));

    }

    //private void GetPromotion()
    //{
    //    TAPromotionList _tapromolist = new TAPromotionList();
    //    TAPromotionDB _tapromodb = new TAPromotionDB();

    //    _tapromolist = _tapromodb.GetProviderTAPromotionList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()));

    //    if (_tapromolist != null)
    //    {
    //        ddlPromotion.DataSource = _tapromolist;
    //        ddlPromotion.DataTextField = "PromotionTitle";
    //        ddlPromotion.DataValueField = "PromotionId";
    //        ddlPromotion.DataBind();
    //    }

    //    ddlPromotion.Items.Insert(0, new ListItem("Select", "-1"));

    //}

    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {

        if (Page.IsValid)
        {
            string _authcode = CE.Security.MySecurity.Encrypt(txtAuthCode.Text, true);
            if (CheckAuthCode(_authcode, 600))
            {
                string origTaInsIdParam = "";

                if (Request.Params["TAID"] != null)
                    origTaInsIdParam = Request.Params["TAID"].ToString();
                else
                    origTaInsIdParam = "";

                //if ((CheckTAExist() && lblTAId.Text == "0") || (CheckTAExist() && lblTAId.Text != origTaInsIdParam))
                //{
                //    lblMessage.Text = "There is an existing plan under this cover type. Pls. delete the existing one first.";
                //}
                //else
                //{
                    TAQuoteResult _tainfo = new TAQuoteResult();
                    TAQuoteResultDB _tainfodb = new TAQuoteResultDB();

                    _tainfo.TAInsId = Convert.ToInt64(lblTAId.Text.Trim());
                    int _trantype = 1;
                    if (_tainfo.TAInsId > 0)
                    {
                        _trantype = 2;
                    }
                    _tainfo.TACompanyId = Convert.ToInt32(ddlProviderCompanyName.SelectedValue);
                    _tainfo.InsurerName = ddlProviderCompanyName.SelectedItem.Text;
                    _tainfo.PlanName = txtPlanName.Text.Trim();
                    _tainfo.PlanType = ddlPolicyType.SelectedValue;
                    _tainfo.TripType = "S";
                    _tainfo.CoverageLevel = ""; //ddlLevelOfCoverage.SelectedValue;
                    _tainfo.DTPD_LessYr70 = Convert.ToInt32(txtAdultLess70.Text.Trim());
                    _tainfo.DTPD_AboveYr70 = Convert.ToInt32(txtAdultAbove70.Text.Trim());
                    _tainfo.DeathPubTrans = Convert.ToInt32(cbDFPT.Checked);
                    _tainfo.DIPC_LessYr70 = Convert.ToInt32(txtDIPCLess70.Text.Trim());
                    _tainfo.DIPC_AboveYr70 = Convert.ToInt32(txtDIPCAbove70.Text.Trim());
                    _tainfo.MedExp_LessYr70 = Convert.ToInt32(txtMedExpLess70.Text.Trim());
                    _tainfo.MedExp_AboveYr70 = Convert.ToInt32(txtMedExpAbove70.Text.Trim());

                    if (cbMedicalEvac.Checked == true)
                    {
                        _tainfo.EmMedEval = 0;
                    }
                    else
                    {
                        _tainfo.EmMedEval = Convert.ToInt32(txtEmergencyMed.Text.Trim());
                    }
                    
                    _tainfo.HospIncome = Convert.ToInt32(txtHospitalInc.Text.Trim());

                    if (cbRepatriation.Checked == false)
                    {
                        _tainfo.BCR = Convert.ToInt32(txtBurial.Text.Trim());
                    }
                    else
                    {
                          _tainfo.BCR = 0;
                    }
                    _tainfo.CompassVisit = Convert.ToInt32(txtCompassionVisit.Text.Trim());
                    _tainfo.ChildCare = Convert.ToInt32(txtChildCare.Text.Trim());
                    _tainfo.PersonalLiability = Convert.ToInt32(txtPersonalLiability.Text.Trim());
                    _tainfo.BagPerEffect = Convert.ToInt32(txtBaggagePerEffect.Text.Trim());
                    _tainfo.BagDelay = Convert.ToInt32(txtBaggageDelay.Text.Trim());
                    _tainfo.TravelDoc = Convert.ToInt32(txtTravelDoc.Text.Trim());
                    _tainfo.DepositTripCancel = Convert.ToInt32(txtDepositTripCancel.Text.Trim());
                    _tainfo.Curtailment = Convert.ToInt32(txtCurtailment.Text.Trim());
                    _tainfo.TravelDelay = Convert.ToInt32(txtTravelDelay.Text.Trim());
                    _tainfo.MissTravelConnection = Convert.ToInt32(txtMissedTravelConn.Text.Trim());
                    _tainfo.TravelOverBook = Convert.ToInt32(txtTravelOverbooked.Text.Trim());
                    _tainfo.PersonalMoney = Convert.ToInt32(txtPersonalMoney.Text.Trim());
                    _tainfo.FBHCP = Convert.ToInt32(txtFBHCP.Text.Trim());
                    _tainfo.ACRR = Convert.ToInt32(txtAddCRCR.Text.Trim());
                    _tainfo.Terrorism = Convert.ToInt32(txtTerrorism.Text.Trim());
                    _tainfo.KidnapHostage = Convert.ToInt32(txtKidnap.Text.Trim());
                    _tainfo.EmtelCharge = Convert.ToInt32(txtEmergencyTelCharges.Text.Trim());
                    _tainfo.Status = Convert.ToBoolean(chkTAStatus.Checked.ToString());
                    _tainfo.RefCEUserID = Convert.ToInt64(Session[General.UserId].ToString());

                    _tainfo.Ninfo1 = Convert.ToInt64(ddlPolicyDoc.SelectedValue);

                    //added 

                    _tainfo.Ninfo3 = Convert.ToInt64(txtPregnancy.Text);
                    _tainfo.Ninfo4 = Convert.ToInt64(txtHospitanIncMax.Text);
                    _tainfo.Ninfo5 = Convert.ToInt32(txtBaggageHour.Text);
                    _tainfo.Ninfo6 = Convert.ToInt32(txtBaggageMax.Text);
                    _tainfo.Ninfo7 = Convert.ToInt32(txtTravelHour.Text);
                    _tainfo.Ninfo8 = Convert.ToInt32(txtTravelMax.Text);

                    _tainfo.Info1 = txtTerrorismHour.Text;
                    _tainfo.Info2 = txtTerrorismMax.Text;
                    _tainfo.Info3 = txtClosureTravelAgent.Text;

                    _tainfo.Info4 = txtPromo.Text;
                    _tainfo.Info5 = cbRepatriation.Checked.ToString();
                    _tainfo.Info6 = cbEmergencyTelActualCost.Checked.ToString();
                    
                    _tainfo.TAInsId = _tainfodb.Insert(_tainfo);

                    if (_tainfo.TAInsId > 0)
                    {
                        InsertProviderAuthTransaction(_tainfo.TAInsId, "TITravelInsurance", _trantype, 600, _authcode, _tainfo.TACompanyId, _tainfo.RefCEUserID);
                        //clearProcess();
                        lblMessage.Text = "Saved successfully!";

                        lblTAId.Text = _tainfo.TAInsId.ToString();

                    }
                    else
                    {
                        lblError.Text = "Saving failed!";
                    }
                //}

            }
            else
            {
                lblMessage.Text = "Wrong auth code!";
            }
        }
    }

    protected void lnkSummary_OnClick(object sender, EventArgs e)
    {
        if (pnlSummary.Visible == false)
        {
            pnlSummary.Visible = true;
            LoadSummary();
            lnkSummary.Text = "Hide Summary";
        }
        else
        {
            pnlSummary.Visible = false;
            lnkSummary.Text = "View Summary";
        }
    }

    private void LoadSummary()
    {
        TAQuoteResultDB _taquoteresultdb = new TAQuoteResultDB();

        DataTable dtResults = new DataTable();
        dtResults = _taquoteresultdb.GetTAQuoteResultDT(Convert.ToInt64(lblTAId.Text.ToString()), ddlPolicyType.SelectedValue.ToString());

        grvDetailsSummary.DataSource = dtResults;
        grvDetailsSummary.DataBind();

    }

    protected void ShowEmergencyMed(object sender, EventArgs e)
    {
        if (cbMedicalEvac.Checked == true)
        {
            txtEmergencyMed.Visible = false;
            rfvEmergencyMed.Enabled = false;
            revEmergencyMed.Enabled = false;
        }
        else
        {
            txtEmergencyMed.Visible = true;
            rfvEmergencyMed.Enabled = true;
            revEmergencyMed.Enabled = true;
        }
    }
    protected void ShowRepatriation(object sender, EventArgs e)
    {
        if (cbRepatriation.Checked == true)
        {
            txtBurial.Visible = false;
            rfvBurial.Enabled = false;
            revBurial.Enabled = false;
        }
        else
        {
            txtBurial.Visible = true;
            rfvBurial.Enabled = true;
            revBurial.Enabled = true;
        }
    }

    protected void ShowClosure(object sender, EventArgs e)
    {
        if (cbClosure.Checked == false)
        {
            txtClosureTravelAgent.Visible = false;
            rfvClosure.Enabled = false;
            revClosure.Enabled = false;
        }
        else
        {
            txtClosureTravelAgent.Visible = true;
            rfvClosure.Enabled = true;
            revClosure.Enabled = true;
        }
    }

    protected void ShowHomeContents(object sender, EventArgs e)
    {
        if (cbHomeContents.Checked == false)
        {
            txtFBHCP.Visible = false;
            rfvFBHCP.Enabled = false;
            revFBHCP.Enabled = false;
        }
        else
        {
            txtFBHCP.Visible = true;
            rfvFBHCP.Enabled = true;
            revFBHCP.Enabled = true;
        }
    }

    protected void ShowKidnapRate(object sender, EventArgs e)
    {
        if (cbKidnap.Checked == false)
        {
            txtKidnap.Visible = false;
            rfvKidnap.Enabled = false;
            revKidnap.Enabled = false;
        }
        else
        {
            txtKidnap.Visible = true;
            rfvKidnap.Enabled = true;
            revKidnap.Enabled = true;
        }
    }

    protected void ShowIsActualCost(object sender, EventArgs e)
    {
        if (cbEmergencyTel.Checked == false)
        {
            cbEmergencyTelActualCost.Visible = false;
        }
        else
        {
            cbEmergencyTelActualCost.Visible = true;
            cbEmergencyTelActualCost.Checked = true;
        }
    }

    protected void ShowEmergencyTelRate(object sender, EventArgs e)
    {
        if (cbEmergencyTelActualCost.Checked == true)
        {
            txtEmergencyTelCharges.Text = "0";
            txtEmergencyTelCharges.Visible = false;
            rfvEmergencyTelCharges.Enabled = false;
            revEmergencyTelCharges.Enabled = false;
        }
        else
        {
            txtEmergencyTelCharges.Visible = true;
            rfvEmergencyTelCharges.Enabled = true;
            revEmergencyTelCharges.Enabled = true;
        }
    }

    public void ClearFields()
    {
        lblTAId.Text = "0";
        txtPlanName.Text = "";        
        txtAdultLess70.Text = "0";
        cbDFPT.Checked = false;
        txtMedExpLess70.Text = "0";
        txtEmergencyMed.Text = "0";
        txtHospitalInc.Text = "0";
        txtBurial.Text = "0";
        txtCompassionVisit.Text = "0";
        txtChildCare.Text = "0";
        txtPersonalLiability.Text = "0";
        txtBaggagePerEffect.Text = "0";
        txtBaggageDelay.Text = "0";
        txtTravelDoc.Text = "0";
        txtDepositTripCancel.Text = "0";
        txtCurtailment.Text = "0";
        txtTravelDelay.Text = "0";
        txtMissedTravelConn.Text = "0";
        txtTravelOverbooked.Text = "0";
        txtPersonalMoney.Text = "0";
        txtFBHCP.Text = "0";
        txtAddCRCR.Text = "0";
        txtTerrorism.Text = "0";
        txtKidnap.Text = "0";
        txtEmergencyTelCharges.Text = "0";
        chkTAStatus.Checked = true;

        ddlPolicyDoc.SelectedIndex = 0;
        txtPromo.Text = "";
        //ddlPromotion.SelectedIndex = 0;

    }

    private void ShowTADetails(Int64 TAId, string CoverType)
    {
        TAQuoteResult _taquoteresult = new TAQuoteResult();
        TAQuoteResultDB _taquoteresultdb = new TAQuoteResultDB();
        _taquoteresult = _taquoteresultdb.GetTAQuoteResult(TAId, CoverType);

        if (_taquoteresult != null)
        {
            ddlPolicyType.Enabled = false;

            lblTAId.Text = _taquoteresult.TAInsId.ToString();
            ddlProviderCompanyName.SelectedValue = _taquoteresult.TACompanyId.ToString();
            ddlPolicyType.SelectedValue = _taquoteresult.PlanType.ToString();
            //ddlLevelOfCoverage.SelectedValue = _taquoteresult.CoverageLevel.ToString();
            txtPlanName.Text = _taquoteresult.PlanName;
            txtAdultLess70.Text = _taquoteresult.DTPD_LessYr70.ToString();
            txtAdultAbove70.Text = _taquoteresult.DTPD_AboveYr70.ToString();
            
            if (_taquoteresult.DeathPubTrans.ToString() == "1")
                cbDFPT.Checked = true;
            else
                cbDFPT.Checked = false;

            txtMedExpLess70.Text = _taquoteresult.MedExp_LessYr70.ToString();
            txtMedExpAbove70.Text = _taquoteresult.MedExp_AboveYr70.ToString();
            txtDIPCLess70.Text = _taquoteresult.DIPC_LessYr70.ToString();
            txtDIPCAbove70.Text = _taquoteresult.DIPC_AboveYr70.ToString();

            if (_taquoteresult.EmMedEval.ToString() == "0")
            {
                cbMedicalEvac.Checked = true;
            }
            else
            {
                cbMedicalEvac.Checked = false;
                txtEmergencyMed.Text = _taquoteresult.EmMedEval.ToString();
            }
            ShowEmergencyMed(this, null);

            
            if (_taquoteresult.Info5.ToString() == "False" || _taquoteresult.Info5.ToString() == "")
            {
                cbRepatriation.Checked = false;

                txtBurial.Text = _taquoteresult.BCR.ToString();
            }
            else
            {
                cbRepatriation.Checked = true;
            }
            ShowRepatriation(this, null);

            txtHospitalInc.Text = _taquoteresult.HospIncome.ToString();
            txtHospitanIncMax.Text = _taquoteresult.Ninfo4.ToString();

            txtPregnancy.Text = _taquoteresult.Ninfo3.ToString();
            txtCompassionVisit.Text = _taquoteresult.CompassVisit.ToString();
            txtChildCare.Text = _taquoteresult.ChildCare.ToString();
            txtPersonalLiability.Text = _taquoteresult.PersonalLiability.ToString();           
            txtBaggagePerEffect.Text = _taquoteresult.BagPerEffect.ToString();

            txtBaggageDelay.Text = _taquoteresult.BagDelay.ToString();
            txtBaggageHour.Text = _taquoteresult.Ninfo5.ToString();
            txtBaggageMax.Text = _taquoteresult.Ninfo6.ToString();

            txtTravelDoc.Text = _taquoteresult.TravelDoc.ToString();
            txtDepositTripCancel.Text = _taquoteresult.DepositTripCancel.ToString();
            txtCurtailment.Text = _taquoteresult.Curtailment.ToString();

            txtTravelDelay.Text = _taquoteresult.TravelDelay.ToString();
            txtTravelHour.Text = _taquoteresult.Ninfo7.ToString();
            txtTravelMax.Text = _taquoteresult.Ninfo8.ToString(); ;

            txtMissedTravelConn.Text = _taquoteresult.MissTravelConnection.ToString();
            txtTravelOverbooked.Text = _taquoteresult.TravelOverBook.ToString();
            txtPersonalMoney.Text = _taquoteresult.PersonalMoney.ToString();

            if (_taquoteresult.Info3.ToString() == "0")
            {
                cbClosure.Checked = false;
            }
            else
            {
                cbClosure.Checked = true;
                txtClosureTravelAgent.Text = _taquoteresult.Info3.ToString();
            }
            ShowClosure(this, null);

            if (_taquoteresult.FBHCP.ToString() == "0")
            {
                cbHomeContents.Checked = false;
            }
            else
            {
                cbHomeContents.Checked = true;
                txtFBHCP.Text = _taquoteresult.FBHCP.ToString();
            }
            ShowHomeContents(this, null);

            txtAddCRCR.Text = _taquoteresult.ACRR.ToString();
            
            txtTerrorism.Text = _taquoteresult.Terrorism.ToString();
            txtTerrorismHour.Text = _taquoteresult.Info1.ToString();
            txtTerrorismMax.Text = _taquoteresult.Info2.ToString();

            if (_taquoteresult.KidnapHostage.ToString() == "0")
            {
                cbKidnap.Checked = false;
            }
            else
            {
                cbKidnap.Checked = true;
                txtKidnap.Text = _taquoteresult.KidnapHostage.ToString();
            }
            ShowKidnapRate(this, null);

            txtEmergencyTelCharges.Text = _taquoteresult.EmtelCharge.ToString();
            if (_taquoteresult.EmtelCharge.ToString().Trim() != "0" || _taquoteresult.Info6 == "True")
            {
                cbEmergencyTel.Checked = true;
                cbEmergencyTelActualCost.Visible = true;
            }
            else
            {
                cbEmergencyTel.Checked = false;
            }

            if (_taquoteresult.Info6 == "True")
            {
                cbEmergencyTelActualCost.Checked = true;
            }
            else
            {
                cbEmergencyTelActualCost.Checked = false;
                txtEmergencyTelCharges.Visible = true;
            }
           
            ShowEmergencyTelRate(this, null);

            chkTAStatus.Checked = Convert.ToBoolean(_taquoteresult.Status.ToString());

            ddlPolicyDoc.SelectedValue = _taquoteresult.Ninfo1.ToString();
            //ddlPromotion.SelectedValue = _taquoteresult.Ninfo2.ToString();

            txtPromo.Text = _taquoteresult.Info4;

        }
    }

    private bool CheckTAExist()
    {
        bool Exists = false;

        //TAQuoteResult _taquoteresult = new TAQuoteResult();
        //TAQuoteResultDB _taquoteresultdb = new TAQuoteResultDB();

        //_taquoteresult = _taquoteresultdb.GetTASelectSingleItemSelected(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), ddlPolicyType.SelectedValue, ddlLevelOfCoverage.SelectedValue);
        

        //if (_taquoteresult != null)
        //{
        //    lblTAId.Text = _taquoteresult.TAInsId.ToString();
        //    Exists = true;

        //}

        return Exists;


    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        rfvAuthCode.Validate();

        if (lblTAId.Text != "0" && txtAuthCode.Text.Trim().Length > 0)
        {
            Int64 _providercompanyid = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
            Int64 _refceuserid = Convert.ToInt64(Session[General.UserId].ToString());
            string _authcode = CE.Security.MySecurity.Encrypt(txtAuthCode.Text, true);

            TAQuoteResultDB _tadb = new TAQuoteResultDB();
            if (CheckAuthCode(_authcode, 600))
            {
                _tadb.Delete(Convert.ToInt64(lblTAId.Text));
                InsertProviderAuthTransaction(Convert.ToInt64(lblTAId.Text), "TATravelInsurance", 3, 600, _authcode, _providercompanyid, _refceuserid);

                Response.Redirect("ViewProviderTravelInsurance.aspx");
            }
            else
            {
                lblMessage.Text = "Wrong auth code!";
            }
        }
    }

    protected void btnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("ViewProviderTravelInsurance.aspx");
    }

    protected bool CheckAuthCode(string strAuthCode, int intAuthCodeType)
    {
        bool _retValue = false;
        ProviderAuthCode _authcode = new ProviderAuthCode();
        ProviderAuthCodeDB _authcodedb = new ProviderAuthCodeDB();
        _authcode = _authcodedb.GetProviderAuthCode(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()), intAuthCodeType, strAuthCode);
        if (_authcode != null)
        {
            _retValue = true;
        }

        return _retValue;
    }

    protected Int64 InsertProviderAuthTransaction(Int64 TransactionId, string TransactionCode, int TransactionType,
        int AuthCodeType, string AuthCode, Int64 ProviderCompanyId, Int64 RefCEUserId)
    {
        ProviderAuthTransaction _authtrans = new ProviderAuthTransaction();
        ProviderAuthTransactionDB _authtransdb = new ProviderAuthTransactionDB();

        _authtrans.TransactionId = TransactionId;
        _authtrans.TransactionCode = TransactionCode;
        _authtrans.TransactionType = TransactionType;
        _authtrans.AuthCode = AuthCode;
        _authtrans.AuthCodeType = AuthCodeType;
        _authtrans.ProviderCompanyId = ProviderCompanyId;
        _authtrans.RefCEUserID = RefCEUserId;

        _authtrans.AuthTransId = _authtransdb.Insert(_authtrans);
        return _authtrans.AuthTransId;
    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            btnSubmit.Enabled = false;
            //btnNew.Enabled = false;
            btnDelete.Enabled = false;
        }
        else if (PageAccess == 200)
        {
            btnSubmit.Enabled = true;
            //btnNew.Enabled = true;
            btnDelete.Enabled = false;
        }
        else if (PageAccess == 300)
        {
            btnSubmit.Enabled = true;
            //btnNew.Enabled = true;
            btnDelete.Enabled = true;
        }
    }


}

